package com.zh.opcua.milo;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;

import java.util.LinkedHashMap;

/**
 * Copyright (C) 广州中和互联网技术有限公司
 *
 * @author 范家微 fanjiawei@borche.cn
 * @date :2020/12/31 12:05
 */
public class WriteSpc {
	public static void main(String[] args) throws Exception {
		OpcUaClient client = OPCUAClientUtils.createOpcUaClient();
		client.connect().get();
		NodeId nodeId = new NodeId(1, 50442);
		//NodeId nodeId = new NodeId(1, "Root.Objects.realtime data.SPCLog");
		Object value = client.readValue(0.0, TimestampsToReturn.Both, nodeId).get().getValue().getValue();
		System.out.println("读出来的值" + value);
		String result = value.toString();
		String[] split = result.split(",");
		System.out.println(split.length== 39);
		LinkedHashMap<String, Object> paraslist = new LinkedHashMap<>();
		// 合模标识位
		DataValue dataValue = client.readValue(0.0, TimestampsToReturn.Both, new NodeId(1, 50277)).get();
		short aShort = Short.parseShort(dataValue.getValue().getValue().toString());
		byte b =(byte)aShort;
		byte[] bytes = Utilities.getBytes(aShort);


		System.out.println(bytes[0]);
		System.out.println((b&0x01));
		System.out.println((b&0x02));
		System.out.println((b&0x04));
		System.out.println((b&0x08));
		System.out.println((b&0x10));
		System.out.println((b&0x20));
		System.out.println((b&0x40));
		System.out.println((b&0x80));
//		paraslist.put("A00002",? 1:0);
//		paraslist.put("A00003",);
//		paraslist.put("A00004",);


	}
}
